package com.niiwoo.civet.user.service.duboo;

import com.alibaba.dubbo.config.annotation.Service;
import com.niiwoo.civet.user.dao.entity.UserImageFile;
import com.niiwoo.civet.user.dto.response.UserImageResponseDTO;
import com.niiwoo.civet.user.enums.UserImgTypeEnum;
import com.niiwoo.civet.user.service.UserImageFileDubboService;
import com.niiwoo.civet.user.service.local.UserIdentityService;
import com.niiwoo.civet.user.service.local.UserImageFileService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
 * 用户图片dubbo服务
 */
@Service(version = "1.0.0")
public class UserImageFileDubboServiceImpl implements UserImageFileDubboService {

    @Autowired
    UserImageFileService userImageFileService;
    @Autowired
    UserIdentityService userIdentityService;

    /**
     * 根据类型获取用户图片列表
     *
     * @param userId 用户ID
     * @param type 图片类型
     */
    public List<UserImageResponseDTO> getImageFileListByType(String userId, UserImgTypeEnum type) {
        return Optional.ofNullable(userImageFileService.getListByType(userId, type)).map(list -> {
            if (list.isEmpty()) {
                return null;
            }
            List<UserImageResponseDTO> imageResponseDTOList = new ArrayList<>(list.size());
            for (UserImageFile i : list) {
                UserImageResponseDTO d = new UserImageResponseDTO();
                d.setId(i.getId());
                d.setCreateTime(i.getCreateTime());
                d.setUpdateTime(i.getUpdateTime());
                d.setDataType(i.getDataType());
                d.setSubType(i.getSubType());
                d.setImgUrl(i.getImgUrl());
                d.setImgReleaseUrl(i.getImgReleaseUrl());
                d.setImgThumbnailUrl(i.getImgThumbnailUrl());
                d.setImgReleaseThumbnailUrl(i.getImgReleaseThumbnailUrl());
                imageResponseDTOList.add(d);
            }
            return imageResponseDTOList;
        }).orElse(null);
    }

    /*private String getHandImage(UserImageResponseDTO d){
        FacePlusPortrait facePlusPortrait = userImageFileService.queryFacePortrait(d.getUserId());
        if(facePlusPortrait==null || !StringUtils.hasText(facePlusPortrait.getBestLiveImage())){
            return d.getImgUrl();
        }
        return facePlusPortrait.getBestLiveImage();
    }*/

}
